<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Call a callback with an array of parameters</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.funchand.html">Function handling 函数</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.call-user-func.html">call_user_func</a></div>
 <div class="up"><a href="ref.funchand.html">Function handling 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.call-user-func-array" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">call_user_func_array</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5)</p><p class="refpurpose"><span class="refname">call_user_func_array</span> &mdash; <span class="dc-title">Call a callback with an array of parameters</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.call-user-func-array-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>call_user_func_array</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$param_arr</code></span>
   )</div>

  <p class="para rdfs-comment">
   Calls the <em><code class="parameter">callback</code></em> given by the first parameter with
   the parameters in <em><code class="parameter">param_arr</code></em>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.call-user-func-array-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">callback</code></em></dt>

     <dd>

      <p class="para">
       The <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> to be called.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">param_arr</code></em></dt>

     <dd>

      <p class="para">
       The parameters to be passed to the callback, as an indexed array.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.call-user-func-array-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the return value of the callback, or <strong><code>FALSE</code></strong> on error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.call-user-func-array-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.3.0</td>
       <td>
        The interpretation of object oriented keywords like <em>parent</em> 
        and <em>self</em> has changed. Previously, calling them using the 
        double colon syntax would emit an <strong><code>E_STRICT</code></strong> warning because 
        they were interpreted as static.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.call-user-func-array-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4998">
    <p><strong>Example #1 <span class="function"><strong>call_user_func_array()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">foobar</span><span style="color: #007700">(</span><span style="color: #0000BB">$arg</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$arg2</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">__FUNCTION__</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"&nbsp;got&nbsp;</span><span style="color: #0000BB">$arg</span><span style="color: #DD0000">&nbsp;and&nbsp;</span><span style="color: #0000BB">$arg2</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />}<br />class&nbsp;</span><span style="color: #0000BB">foo&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">bar</span><span style="color: #007700">(</span><span style="color: #0000BB">$arg</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$arg2</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">__METHOD__</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"&nbsp;got&nbsp;</span><span style="color: #0000BB">$arg</span><span style="color: #DD0000">&nbsp;and&nbsp;</span><span style="color: #0000BB">$arg2</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /><br /></span><span style="color: #FF8000">//&nbsp;Call&nbsp;the&nbsp;foobar()&nbsp;function&nbsp;with&nbsp;2&nbsp;arguments<br /></span><span style="color: #0000BB">call_user_func_array</span><span style="color: #007700">(</span><span style="color: #DD0000">"foobar"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"one"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"two"</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;Call&nbsp;the&nbsp;$foo-&gt;bar()&nbsp;method&nbsp;with&nbsp;2&nbsp;arguments<br /></span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">call_user_func_array</span><span style="color: #007700">(array(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"bar"</span><span style="color: #007700">),&nbsp;array(</span><span style="color: #DD0000">"three"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"four"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
foobar got one and two
foo::bar got three and four
</pre></div>
    </div>
   </div>
   <div class="example" id="example-4999">
    <p><strong>Example #2 <span class="function"><strong>call_user_func_array()</strong></span> using namespace name</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">namespace&nbsp;</span><span style="color: #0000BB">Foobar</span><span style="color: #007700">;<br /><br />class&nbsp;</span><span style="color: #0000BB">Foo&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$name</span><span style="color: #007700">}</span><span style="color: #DD0000">!\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;As&nbsp;of&nbsp;PHP&nbsp;5.3.0<br /></span><span style="color: #0000BB">call_user_func_array</span><span style="color: #007700">(</span><span style="color: #0000BB">__NAMESPACE__&nbsp;</span><span style="color: #007700">.</span><span style="color: #DD0000">'\Foo::test'</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'Hannes'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;As&nbsp;of&nbsp;PHP&nbsp;5.3.0<br /></span><span style="color: #0000BB">call_user_func_array</span><span style="color: #007700">(array(</span><span style="color: #0000BB">__NAMESPACE__&nbsp;</span><span style="color: #007700">.</span><span style="color: #DD0000">'\Foo'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'test'</span><span style="color: #007700">),&nbsp;array(</span><span style="color: #DD0000">'Philip'</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Hello Hannes!
Hello Philip!
</pre></div>
    </div>
   </div>
   <div class="example" id="example-5000">
    <p><strong>Example #3 Using lambda function</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$func&nbsp;</span><span style="color: #007700">=&nbsp;function(</span><span style="color: #0000BB">$arg1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$arg2</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$arg1&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">$arg2</span><span style="color: #007700">;<br />};<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">call_user_func_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$func</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">)));&nbsp;</span><span style="color: #FF8000">/*&nbsp;As&nbsp;of&nbsp;PHP&nbsp;5.3.0&nbsp;*/<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
int(8)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.call-user-func-array-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Before PHP 5.4, referenced variables in <em><code class="parameter">param_arr</code></em>
    are passed to the function by reference, regardless of whether the function
    expects the respective parameter to be passed by reference. This form of
    call-time pass by reference does not emit a deprecation notice, but it is
    nonetheless deprecated, and has been removed in PHP 5.4.
    Furthermore, this does not apply to internal functions, for which
    the function signature is honored. Passing by value when the function
    expects a parameter by reference results in a warning and having
    <span class="function"><a href="function.call-user-func.html" class="function">call_user_func()</a></span> return <strong><code>FALSE</code></strong> (there is, however, an
    exception for passed values with reference count = 1, such as in literals,
    as these can be turned into references without ill effects — but also
    without writes to that value having any effect —; do not rely
    in this behavior, though, as the reference count is an implementation
    detail and the soundness of this behavior is questionable).
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">在函数中注册有多个回调内容时(如使用
<span class="function"><a href="function.call-user-func.html" class="function">call_user_func()</a></span> 与 <span class="function"><strong>call_user_func_array()</strong></span>)，如在前一个回调中有未捕获的异常，其后的将不再被调用。</p></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.call-user-func-array-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.call-user-func.html" class="function" rel="rdfs-seeAlso">call_user_func()</a> - Call the callback given by the first parameter</span></li>
    <li class="member"><a href="language.pseudo-types.html#language.types.callback" class="link">callback</a> 类型的信息</li>
    <li class="member"><span class="methodname"><a href="reflectionfunction.invokeargs.html" class="methodname" rel="rdfs-seeAlso">ReflectionFunction::invokeArgs()</a> - Invokes function args</span></li>
    <li class="member"><span class="methodname"><a href="reflectionmethod.invokeargs.html" class="methodname" rel="rdfs-seeAlso">ReflectionMethod::invokeArgs()</a> - Invoke args</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.funchand.html">Function handling 函数</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.call-user-func.html">call_user_func</a></div>
 <div class="up"><a href="ref.funchand.html">Function handling 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
